
//npm install 
//node app,js
var express = require('express');
var app = express();
var http = require('http');
var bodyParser = require('body-parser');
// 创建 application/x-www-form-urlencoded 编码解析
var urlencodedParser = bodyParser.urlencoded({ extended: false })

app.use(express.static('public'));
//app.use(bodyParser.json({type:‘application/*+json’}));
app.use(bodyParser.text());
//设置跨域访问
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});



let  vip = require('./public/vip.js');
let  loginapi = require('./public/loginapis.js');
let  role = require('./public/role.js');



let diclist = require('./public/diclist.js');
let notice = require('./public/notice.js');
let receptionroom = require('./public/receptionroom.js');
let information = require('./public/information.js');
let mark = require('./public/marklist.js');
let markpromise= require('./public/markpromiselist.js');
let oilprice=require('./public/oilpricelist.js');

let apis = {};
Object.assign(apis,vip.apis,loginapi.apis,role.apis,diclist.apis,notice.apis,receptionroom.apis,information.apis,mark.apis,markpromise.apis,oilprice.apis);

//请求总入口
app.post('/admin',urlencodedParser, function(req, res) {
	 res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
	let data = req.body;
	let params = data.data;
	console.log(data.url)
	
	
	
	console.log(params)
	let database = apis;
	let res_data = database[data.url];
	console.log(res_data);
	let respond = {
		code:1,
		data:res_data,
		message:''
	}
    res.send(respond);
});





var server = app.listen(8088, function () {
 
  var host = server.address()
  var port = server.address().port
 
  console.log("应用实例，访问地址为", host, port)
 
})